<?php

/*
 * TODO need to move this into a config file of some sort, probably using a registry
 */
$default_controller = 'test';


$path_info = isset($_SERVER['PATH_INFO']) ? explode("/", trim($_SERVER['PATH_INFO'], "/")) : NULL;

// Get the controller and the method from the URI
$c = $path_info ? $path_info[0] : $default_controller;
$m = isset($path_info[1]) ? $path_info[1] : 'main';

// Check if the controller exists
if(file_exists(ROOT.'app/controllers/' .  strtolower($c) . '.php'))
{
    include ROOT.'app/controllers/' . strtolower($c) . '.php';
    $controller = new $c();

    if(method_exists($controller, $m)):
        $controller->$a();
    else:
        trigger_error ("Method '" . $m . "' does not exist in controller '" . $c . "'.<br>", E_USER_WARNING);
    endif;
}
else
{
    trigger_error("You must specify a default controller, or use a valid controller in the URI.<br>", E_USER_ERROR);
}
